package models;

import com.google.gdata.data.media.mediarss.MediaThumbnail;
import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.PhotoEntry;
import models.crudsiena.SienaSupport;
import siena.*;
import siena.embed.Embedded;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Cyril
 * Date: 07.08.11
 * Time: 17:57
 * To change this template use File | Settings | File Templates.
 */
@Table("picasa_album")
public class PicasaAlbum extends SienaSupport {
    @Id(Generator.NONE)
    public Long id;

    @Column("version")
    @Max(50)
    public String version;

    @Column("title")
    public String title;

    @Filter("album")
    public Query<PicasaPhoto> photos;

    @Embedded
    public List<String> thumb;

    public static Query<PicasaAlbum> all() {
        return Model.all(PicasaAlbum.class);
    }

    public static PicasaAlbum getFromEntry(AlbumEntry entry) {
        PicasaAlbum album = new PicasaAlbum();
        album.id = Long.valueOf( PicasaPhoto.parseId(entry.getId()) );
        album.version = entry.getUpdated().toString();
        album.title = entry.getTitle().getPlainText();
        album.thumb = new ArrayList<String>();
        for (MediaThumbnail thumb : entry.getMediaThumbnails())
            album.thumb.add( thumb.getUrl() );
        return album;
    }
}
